<?php
/**
 * Created by PhpStorm.
 * User: zhongbaitong
 * Date: 2020/1/13
 * Time: 15:09
 */

namespace app\im\home;

use app\common\controller\ApiBase;
use app\im\model\ChatService as CSModel;

/**
 * 客服消息
 * Class ChatService
 * @package app\im\home
 */
class ChatService extends ApiBase
{
    // 最新一条
    public function latest(){
        $user_id = $this->user["id"];

        $data = CSModel::getTheLatest($user_id);

        return $this->apiReturn(compact("data"));
    }

    /**
     * 全部记录
     * @return \think\response\Json
     * @throws \app\common\exception\ApiError
     */
    public function lists(){
        $input = $this->getInput();
        $input["user_id"] = $this->user["id"];

        // 记录
        $data = CSModel::getLists($input);
        // 设置已读
        CSModel::setReaded($input["user_id"]);

        return $this->apiReturn($data);
    }

}